#ifndef EQUALIZERVIEW_H
#define EQUALIZERVIEW_H

#include <QWidget>
#include <QPainter>
#include <QPainterPath>
#include <QMouseEvent>
#include <QWheelEvent>
#include <QGridLayout>
#include <QPushButton>
#include "equalizergroup.h"


#define HZ_POINTS   9
#define EQ_BANDS    8



class EqualizerView : public QWidget
{
    Q_OBJECT
public:
    explicit EqualizerView(EqualizersGroup *group, QWidget *parent = nullptr);

private:
    QBrush brushBackground;
    QPen penFrame;
    QPen penAxisXY;
    QFont fontAxisText;
    QPen penLines;
    QPen penEqCurve[EQ_BANDS];
    QBrush brushEqCurve[EQ_BANDS];
    const QColor curveColors[EQ_BANDS]={
        QColor(143, 188, 143),
        QColor(250, 235, 215),
        QColor(0, 255, 255),
        QColor(127, 255, 212),
        QColor(138, 43, 226),
        QColor(222, 184, 135),
        QColor(95, 158, 160),
        QColor(127, 255, 0),
    };

    double hzLogDiff;

    const double pi = 3.141592653589793;
    const double yHz[HZ_POINTS]=    {20,50,100,200,300,1000,4000,12000,24000};
    const QString yHzStr[HZ_POINTS]={"20","50","100","200","300","1K","4K","12K","24K"};
    QList<double>xAxisScaleCoe;
    QList<double> eqHandleXAxis;

    QList<QList<QPointF>> eqPoints;
    QList<QPointF> eqResultCurvePoints;
    QList<double> eqCurveXaxis;

    QRectF localRect;
    int currentSelect;

    void updateEqCurvePath(int num,double centerFreq, double Q,double gainDB);
    void updateEqResultCurvePath(void);

    EqualizersGroup *eqGroup;
    double freqRespStart;
    double freqRespEnd;
    double freqRespInterval;
    // QPushButton btn_clear;
    // QGridLayout layout_main;
    // QWidget widget_eq;
public:
    void set_all_gain_to_zero(void);

protected:
    void paintEvent(QPaintEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void wheelEvent(QWheelEvent *event) override;

signals:

    void equalizerParamUpdate(int num,double cf,double q,double gainDb);

    void sig_eq_select(int index);
    void sig_eq_select_release(int index);
    void sig_eq_select_change(int index);

public slots:
    void updateView(void);

};

#endif // EQUALIZERVIEW_H
